Python for Beginners : An Essential Guide to Easy Learning with Basic Exercises : Python programming Crash Course for Data Analysis and for Beginner Hackers by Walsh Conley

Python for Beginners : An Essential Guide to Easy Learning with Basic Exercises : Python programming Crash Course for Data Analysis and for Beginner Hackers by Walsh Conley

Author:Walsh, Conley [Walsh, Conley]
Language: eng
Format: epub, azw3, pdf
Published: 2020-06-05T16:00:00+00:00


Chapter 10:

Exception Handling in the Python Language

The next topic that we need to spend some time exploring in this guidebook is the idea of exception handling. There are going to be times when your code tries to show up some errors or other problem inside the code that you are doing, and this is where the exception is going to occur. Knowing when to recognize these exceptions, how to handle them, and even how to make some of your own can make a big difference in how well you are able to do some of your own coding in Python.

These exceptions are going to be brought up by the compiler in a lot of different situations, and sometimes, they are going to look like a simple error message like you may have seen on your own computer before. It is important to really read through any of these exceptions that come up in your code and read through them so that you can learn what they are about, and how you can handle them properly at the same time. This isn’t meant to be something to scare you, but there are things that you can do to handle these exceptions and to make sure that you are going to be able to handle them in the proper manner.

Now, there are going to be a few exceptions that are already recognized inside the library that you are using in Python. If you want to write out a code with them in there, or if you find that the user is trying to do something that isn’t proper for your program, then the compiler is going to send out an exception about this in order to get it to stop. In some cases, the program you are writing is going to need some extra limitations in place to handle it, and you can raise up, after creating, your own exception.

A good example of an exception that your compiler is automatically going to raise up is when you or the user is to divide it by zero. The compiler is then going to recognize that this is something the user is not able to do, and it is going to send out that exception as an alert. It can also be something that is going to be called up if you, as the programmer, are trying to call up a function and the name is not spelled in the proper manner so there is no match present to bring up.

There are a few different exceptions that are automatically found in your Python library. It is a good idea to take some time to look through them and recognize these exceptions so you can recognize them later on. Some of the most common exceptions that you need to worry about include:

Finally—this is the action that you will want to use to perform cleanup actions, whether the exceptions occur or not.

Assert—this condition is going to trigger the exception inside of the code

Raise—the raise command is going to trigger an exception manually inside of the code.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.